import { defineStore } from 'pinia';
import { getItem, setItem, removeItem } from '@/utils/storage';
const COLLAPSE = 'VEA-COLLAPSE';
interface tabsQuery {
  title:string | any,
  name:string | any
}
export const control = defineStore('control', {
  state: () => ({
    isCollapse:getItem(COLLAPSE) as boolean,
    isFloatDialog:false as boolean,
    editableTabs:getItem('hypdeditableTabs') as Array<tabsQuery> || [], // 历史打开菜单
    editableTabsValue:'', // 选中的历史菜单
    webh5:false as boolean,
  }),
  actions: {
    setFloatDialog(data: boolean) {
      this.isFloatDialog = data
      if(data) {
        this.isCollapse = true
      }
    },
    setWebh5(data: boolean) {
      this.webh5 = data
      this.isFloatDialog = data
    },
    setCollapse(data: boolean) {
      this.isCollapse = data
      // 保存到localStorage
      setItem(COLLAPSE, data)
    },
    clearCollapse() {
      this.isCollapse = false
      removeItem(COLLAPSE)
    },
    editEditableTabs(list:Array<tabsQuery>){
      this.editableTabs = list
      setItem('hypdeditableTabs',list)
    },
    removeEditableTabs() {
      removeItem('hypdeditableTabs')
      this.editableTabs = []
      this.editableTabsValue = ''
    }
  },
})